<!-- ALm6fM1w9mN4yNyZw7idLJmzc6ykb4BSGVRVoWjXT6eYVkpUwAJFoMFauAfKS9kcXGra0gFvEG3rdJOC+HTfPLC1eSSKZvPMjJFGZo+V1kbQwoeX3jvjiEEy6Ni7l4li+lnUy0Y/0APaihKDNE8O22sUaA6U10kB2wlJjfXUb6CAcWRVhQloUFk= -->
<link rel="stylesheet" type="text/css" href="http://gadglet.appspot.com/static/gwt/standard/standard.css"/>
<script src="http://gadglet.appspot.com/static/js/popup.js"></script>

<div id="message" class="div-hidden"></div>
<div id="approval" class="div-hidden">
     <a href="#" id="personalize">__MSG_gadgetMsgPleaseApproveContacts__</a>
</div>

<div id="waiting" class="div-hidden">
   <a href="#" id="approvaldone"> __MSG_gadgetMsgApproveInProcess__</a>
</div>
<div id="ananGadgets" class="div-hidden"><div id="ananGadgetsRoot" ></div></div>

 <script type="text/javascript">
    function showOneSection(toshow) {
      var sections = [ 'message', 'approval', 'waiting','ananGadgets' ];
      for (var i=0; i < sections.length; ++i) {
        var s = sections[i];
        var el = document.getElementById(s);
        if (s === toshow) {
          el.style.display = "block";
        } else {
          el.style.display = "none";
        }
      }
    }

    function testConn() {
        var params = {};
        url = "http://www.google.com/m8/feeds/contacts/default/base?alt=json&max-results=1";
        params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.JSON;
        params[gadgets.io.RequestParameters.AUTHORIZATION] = gadgets.io.AuthorizationType.OAUTH;
        params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.GET;

        gadgets.io.makeRequest(url, function (response) { 
          if (response.oauthApprovalUrl) {
            var popup = shindig.oauth.popup({
              destination: response.oauthApprovalUrl,
              windowOptions: null,
              onOpen: function() { showOneSection('waiting'); },
              onClose: function() { testConn(); }
            });
        
            var personalize = document.getElementById('personalize');
            personalize.onclick = popup.createOpenerOnClick();
            var approvaldone = document.getElementById('approvaldone');
            approvaldone.onclick = popup.createApprovedOnClick();
            showOneSection('approval');
          } else if (response.data) {
            showOneSection('ananGadgets');
           
          } else {
            var message = document.getElementById('message');
            var prefs = new gadgets.Prefs();
            var err = document.createTextNode(prefs.getMsg("approveError"));
            message.appendChild(err);
            showOneSection('message');
          }
        }, params);
      }
      
      gadgets.util.registerOnLoadHandler(testConn);
 </script>    